<%-- 
    Document   : Books
    Created on : Mar 7, 2014, 11:30:10 AM
    Author     : mishra
--%>

<%@page import="BookType.BookTypeBean"%>
<%@page import="BookCategory.BookCategoryBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Vector"%>
<!doctype html>
<%
    try {
        if (session.getAttribute("uid") != null) {
            if (session.getAttribute("Books").toString().equals("1")) {
%>
<%String to = "", status = "", msg = "";%>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Ramgovind Automated System</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="/RIT/css/bootstrap.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap-responsive.css">
        <link rel="stylesheet" href="/RIT/css/jquery.fancybox.css">
        <link rel="stylesheet" href="/RIT/css/uniform.default.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap.datepicker.css">
        <link rel="stylesheet" href="/RIT/css/jquery.cleditor.css">
        <link rel="stylesheet" href="/RIT/css/jquery.plupload.queue.css">
        <link rel="stylesheet" href="/RIT/css/jquery.tagsinput.css">
        <link rel="stylesheet" href="/RIT/css/jquery.ui.plupload.css">
        <link rel="stylesheet" href="/RIT/js/tableTools/css/TableTools.css">
        <link rel="stylesheet" href="/RIT/css/chosen.css">
        <link rel="stylesheet" href="/RIT/css/chosen.css">
        <link rel="stylesheet" href="/RIT/css/style.css">
        <link rel="stylesheet" href="/RIT/css/iconfont.css">
        <link rel="stylesheet" href="/RIT/css/lightBox.css">
        <script src="/RIT/ajax/ajax.js"></script>
        <script type="text/javascript">
            function loadBooks()
            {
                //document.getElementById('ILoader').setAttribute("style", "visibility: visible;width: 250px;height: 250px;position: absolute;top: 50%;left:50%;margin-top: -80px;margin-left: -40px;background:url(/RIT/img/loader.gif) no-repeat;z-index: 667999;background-size:200px 200px;");

                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        document.getElementById('ctbody').innerHTML = xmlhttp.responseText;
                        document.getElementById('ILoader').removeAttribute("style");
                        var str = document.body.innerHTML;
                        var res = str.replace(/null/g, "***");
                        document.body.innerHTML = res;
                    }
                }
                xmlhttp.open("POST", "/RIT/BookList", true);
                xmlhttp.send();
            }
            function deleteBooksConfirm(i, j) {
                document.getElementById('myModal').className = 'modal';
                document.getElementById('delthis').value = i;
                document.getElementById('delthe').value = j;
            }
            function Cancel() {
                document.getElementById('myModal').className = 'modal hide';
            }
            function deleteBook()
            {
                var id = document.getElementById('delthis').value;
                var trid = document.getElementById('delthe').value;
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        var temp = xmlhttp.responseText;
                        if (temp != 0)
                        {
                            var table = document.getElementById(trid);
                            for (var j = 7; j >= 0; j--)
                            {
                                table.deleteCell(j);
                                document.getElementById('myModal').className = 'modal hide';
                            }
                        }
                        else
                        {
                            alert("This Data is Used at Some Other Place");
                            document.getElementById('myModal').className = 'modal hide';
                        }
                    }
                }
                xmlhttp.open("POST", "/RIT/DeleteBooks?id=" + id, false);
                xmlhttp.send();
            }
            function viewBookDetails(id)
            {
                //document.getElementById('iconLoader').setAttribute("style", "visibility: visible;width: 100%;height: 100%;position: fixed;z-index: 666999;top: 0;left: 0;right: 0;bottom: 0;background: url(/BASIL/images/patterns/3-1.png) repeat;opacity: 0.5;");
                //document.getElementById('ILoader').setAttribute("style", "visibility: visible;width: 120px;height: 120px;position: absolute;top: 50%;left:50%;margin-top: -80px;margin-left: -40px;background:url(/BASIL/images/loader.gif) no-repeat;z-index: 667999;");
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        //document.getElementById('iconLoader').removeAttribute("style");
                        //document.getElementById('ILoader').removeAttribute("style");
                        document.getElementById('fade').style.display = 'block';
                        document.getElementById("detailDiv").innerHTML = xmlhttp.responseText;
                        $("#detailDiv").fadeIn(1000);
                    }
                }
                xmlhttp.open("POST", "/RIT/ShowBookDetails?aId=" + id, true);
                xmlhttp.send();
            }
            function getBookType(cid)
            {
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        document.getElementById('btype').innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("POST", "/RIT/getBookType?cid=" + cid, false);
                xmlhttp.send();
            }
            function loadBooksearch()
            {
                var bname=document.getElementById('bname').value;
                var btype=document.getElementById('btype').value;
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {
                    xmvlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        document.getElementById('ctbody').innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("POST", "/RIT/SearchBook?bname="+bname+"&btype="+btype, true);
                xmlhttp.send();
            }
        </script>
        
    </head>
    <body onload="loadBooks()">					
        <!--Display Details Divs-->
        <div id="detailDiv" class="white_content"></div>
        <div id="fade" class="black_overlay"></div>
        <%@include file="/topheader.html" %>
        <%@include file="/settingheader.html" %>
        <div class="main">
            <div class="modal hide" id="myModal">
                <div class="modal-header">
                    <button type="button" class="close" onclick="document.getElementById('myModal').className = 'modal hide'"><img src="/RIT/img/mclose.png"></button>
                    <h3 style=" color: red;">Warning...</h3>
                </div>
                <div class="modal-body">
                    <p>Are you sure to delete?</p>
                </div>
                <div class="modal-footer">
                    <input type="hidden" value="" id="delthis">
                    <input type="hidden" value="" id="delthe">
                    <a href="#" class="btn btn-primary" onclick="deleteBook()">Ok </a>
                    <a href="#" class="btn btn-success" onclick="Cancel()">Cancel</a>
                </div>
            </div>
            <div class="container-fluid">
                <%@include file="/Settings/dbsidenav.html"%>
                <div class="content">
                    <%if (session.getAttribute("status") != null) {
                            status = session.getAttribute("status").toString();
                            msg = session.getAttribute("msg").toString();
                    %>
                    <div class="alert alert-success alert-block">
                        <a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a>
                        <h4 class="alert-heading"> <%=status%></h4>
                        <%=msg%>

                    </div>
                    <%session.removeAttribute("status");
                            session.removeAttribute("msg");
                        }%>
                    <div class="row-fluid">
                        <div class="box">
                            <div class="box-head tabs">
                                <h3>Book List</h3>
                                <div style="float:right;display:flex">
                                    <div class="input-prepend input-append">
                                        <select name="bcat" id="bcat" class='{required:true}' onchange="getBookType(this.value)">
                                            <option value=''>Select Book Category</option>
                                                    <%
                                                        Vector<Object> list=BookCategory.Query.viewAll();
                                                        Iterator it = list.iterator();
                                                        while (it.hasNext()) {
                                                            BookCategoryBean bcb=(BookCategoryBean) it.next();

                                                    %>
                                                    <option value="<%=bcb.getBookCategoryId()%>"><%=bcb.getBookCategory()%></option>
                                                    <%}%>
                                                </select>
                                        <span class="add-on"></span>
                                        <select name="btype" id="btype" class='{required:true}'>
                                            <option value=''>Select Book Type</option>
                                        </select>
                                        <span class="add-on"></span>
                                        <input type="text" class="input-square" placeholder="Book Name" name="bname" id="bname" style="width: 100px;"><span class="add-on"><a href="#" class="ficon-search" onclick="loadBooksearch()"></a></span>
                                    </div>
                                    <a href="/RIT/Settings/Database/AddBook.jsp" style="margin-left: 20px;">
                                        <button class="btn btn-success">Add Books</button>
                                    </a>
                                </div>
                            </div>
                            <div class="box-content box-nomargin">
                                <table class='table table-striped dataTable-noheader dataTable-nofooter table-bordered' id="ct">
                                    <thead>
                                        <tr>
                                            <th>Category</th>
                                            <th>Type</th>
                                            <th>Name</th>
                                            <th>Publisher</th>
                                            <th>Author</th>
                                            <th>Year</th>
                                            <th>Quantity</th>
                                            <th style="width:150px">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody id="ctbody">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>	
            </div>
        </div>
    </div>	
    <script src="/RIT/js/jquery.js"></script>
    <script src="/RIT/js/less.js"></script>
    <script src="/RIT/js/bootstrap.min.js"></script>
    <script src="/RIT/js/jquery.uniform.min.js"></script>
    <script src="/RIT/js/bootstrap.timepicker.js"></script>
    <script src="/RIT/js/bootstrap.datepicker.js"></script>
    <script src="/RIT/js/chosen.jquery.min.js"></script>
    <script src="/RIT/js/jquery.fancybox.js"></script>
    <script src="/RIT/js/plupload/plupload.full.js"></script>
    <script src="/RIT/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
    <script src="/RIT/js/jquery.cleditor.min.js"></script>
    <script src="/RIT/js/jquery.inputmask.min.js"></script>
    <script src="/RIT/js/jquery.tagsinput.min.js"></script>
    <script src="/RIT/js/jquery.mousewheel.js"></script>
    <script src="/RIT/js/jquery.dataTables.min.js"></script>
    <script src="/RIT/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/RIT/js/jquery.textareaCounter.plugin.js"></script>
    <script src="/RIT/js/ui.spinner.js"></script>
    <script src="/RIT/js/jquery.cookie.js"></script>
    <script src="/RIT/js/tableTools/js/TableTools.min.js"></script>
    <script src="/RIT/js/custom.js"></script><script src="js/demo.js"></script>
    <script src="/RIT/js/iconfont.js"></script>
    <style>
        b{color: rgb(26, 115, 212);}
    </style>

    <script>
                                            function quickClose() {
                                                $("#detailDiv").fadeOut(500);
                                                $("#fade").fadeOut(100);
                                            }
    </script>
</body>

</html>
<%} else {
%>
<script type="text/javascript">
    alert("You Are Not Authorised");
    window.history.back();
</script>
<%             }
        } else {
            request.setAttribute("msg", "You Are Not Authorised! Please Contact to System Administrator!");
            request.setAttribute("value", "0");
            getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
        }
    } catch (Exception e) {
        request.setAttribute("msg", "Please Contact to System Administrator!");
        request.setAttribute("value", "0");
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
%>